<?php
require_once 'kelas/record.php';
require_once 'kelas/fungsi.php';
require_once 'kelas/amankanParam.php';

require_once 'kelas/kategori.php';
require_once 'kelas/produk.php';
require_once 'kelas/transaksi.php';
echo $objFungsi->buatJudul('CART',110);
?>


<link rel="stylesheet" type="text/css" href="<?php echo BASEURL;?>css/isi.css" />
<form name="formCart" method="POST" action="<?php echo BASEURL.'proses/belanja.php?on=editCartItems';?>">
    <div class="frame_table_order">
        <table width="100%" cellpadding="5" cellspacing="0" border="1" style="border-collapse:collapse">
            <thead>
                <tr align="center" valign="middle" bgcolor="#CCCCCC">
                    <th><span class="font_sub_judul_2">No</span></th>
                    <th><span class="font_sub_judul_2">Gambar</span></th>
                    <th><span class="font_sub_judul_2">Nama</span></th>
                    <th><span class="font_sub_judul_2">Harga</span></th>
                    <th><span class="font_sub_judul_2">Qty</span></th>
                    <th><span class="font_sub_judul_2">Subtotal</span></th>
                    <th><span class="font_sub_judul_2">Hapus</span></th>
                </tr>
            </thead>
            <tbody>
                <?php
                $dtS = $objTransaksi->detailTemp();
                if ($dtS['total'] == 0) {
                    ?>
                    <tr class="font_isi_judul" align="center" valign="middle">
                        <td align="center" colspan="7"><span class="font_sub_judul_2" style="text-align:center">(belum ada item)</span></td>

                    </tr>
                    <?php
                } else {
                    $no=1;
                    $total = 0;
                    foreach ($dtS['result'] as $k=>$value){
                        $hrg = $value['diskon']>0?($value['harga_jual']-($value['harga_jual']*($value['diskon']/100))):$value['harga_jual'];
                        ?>
                        <tr class="font_isi_judul" align="center" valign="middle">
                            <td><span class="font_sub_judul_2"><?php echo $no++;?></span></td>
                            <td><span class="font_sub_judul_2">
                                <a href="<?php echo BASEURL.'?v=detail&id='.$value['id']; ?>">
                                    <img style="width:50px;height:50px" src="<?php echo BASEURL.'produk/'.$value['gambar']; ?>"/>
                                </a></span>
                            </td>
                            <td><span class="font_sub_judul_2"><?php echo $value['nama'];?></span></td>
                            <td style="text-align: right">
                                <span class="font_sub_judul_2">
                                    <?php echo ($value['diskon']>0)?"<span style='text-decoration:line-through;color:red;font-size:small'>".number_format($value['harga_jual'],0,'.',',')."</span><br/>":"";echo number_format($hrg,0,'.',',')?></span></td>
                                    <td><span class="font_sub_judul_2">
                                        <input value="<?php echo $value['jumlah_buy'];?>" class="text_box_50 nomor" name="buy[<?php echo (string)$k;?>]" />
                                        <input value="<?php echo $value['id'];?>" type="hidden" class="text_box_50" name="id[<?php echo (string)$k;?>]" />
                                    </span>
                                </td>
                                <td style="text-align: right"><span class="font_sub_judul_2"><?php $total +=$hrg*$value['jumlah_buy'] ;echo number_format($hrg*$value['jumlah_buy'],0,'.',','); ?></span></td>
                                <td>
                                    <span class="font_sub_judul_2">
                                        <a onclick="return confirm('Hapus <?php echo $value['nama']; ?> dari Cart?');" href="<?php echo BASEURL.'proses/belanja.php?on=hapusCartItem&id='.$value['id'];?>" class="button">Hapus</a></span></td>
                                    </tr>
                                    <?php
                                }
                            }
                            ?>

                        </tbody>
                        <tfoot>
                            <tr>
                                <th colspan="6" style="text-align: right">Total: <input style="text-align:right" type="text" class="option" disabled="disabled" value="<?php echo isset($total)? "Rp. ".number_format( $total,0,'.',','):0; ?>" />
                                </th>
                                <th style="text-align:center"><input type="submit" <?php echo $dtS['total']>0?"":"disabled='disabled'"; ?> class="option" value="Ubah" />
                                </th>

                            </tr>

                        </tfoot>
                    </table>
                </div>
            </form>
            <div class="cart-option">
                <a href="<?php echo BASEURL;?>index.php?v=store" class="option">Lanjutkan Belanja</a>
                <?php 
                if ($dtS['total']>0) { ?>
                <a href="<?php echo BASEURL;?>index.php?v=<?php echo (isset($_SESSION['userlogin']) && is_array(($_SESSION['userlogin'])) && count(($_SESSION['userlogin']))>3)?"checkout":"newaccount"; ?>" class="option">Selesai Belanja</a>
                <?php } ?>
            </div>
            <script type="text/javascript">
            var dataSes = <?php echo json_encode($objTransaksi->detailTemp());?>;
            $(document).ready(function(){
                $(document).find('form[name="formCart"]').validate({
                    rules:{
                        <?php 
                        foreach ($dtS['result'] as $key => $value) {
                            ?>
                            "buy[<?php echo (string)$k ?>]":{
                                number:true
                            },
                            <?php }
                            ?>
                        },
                        messages:{
                        <?php 
                        foreach ($dtS['result'] as $key => $value) {
                            ?>
                            "buy[<?php echo (string)$k ?>]":{
                                number:"Isi hanya angka."
                            },
                            <?php }
                            ?>
                        },
                    });
            });
            </script>
